package com.team7.happycommunity.propertymanagement.controller;

import com.github.pagehelper.PageInfo;
import com.team7.happycommunity.propertymanagement.common.CommonResult;
import com.team7.happycommunity.propertymanagement.pojo.OwnerParkingApply;
import com.team7.happycommunity.propertymanagement.pojo.ParkingInfo;
import com.team7.happycommunity.propertymanagement.service.OwnerParkingApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/parkingapplication")
@Controller
public class ParkingApplicationController {

    @Autowired
    OwnerParkingApplyService ownerParkingApplyService;

    @PostMapping("/refuse")
    @ResponseBody
    public CommonResult resuse(Integer id){
        int result = ownerParkingApplyService.refuse(id);
        return (result == 0)?CommonResult.failed():CommonResult.success();
    }

    @PostMapping("/pass")
    @ResponseBody
    public CommonResult pass(Integer id){
        int result = ownerParkingApplyService.pass(id);
        return (result == 0)?CommonResult.failed():CommonResult.success();
    }

    @RequestMapping("/list")
    @ResponseBody
    public CommonResult getList(@RequestParam(value="page",defaultValue = "1",required = false) Integer currentPage,
                                           @RequestParam(value="limit",defaultValue = "5",required = false) Integer pageSize,
                                           @RequestParam(value = "username",defaultValue = "null",required = false) String username){
        PageInfo info = null;
        try{
            List<OwnerParkingApply> list = ownerParkingApplyService.getList(currentPage,pageSize,username);
            info = new PageInfo(list);
            return CommonResult.success(info);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed();
        }
    }

}
